package com.wyp168.leetcode;

/**
 * @ClassName ReverseBits
 * @Description TODO
 * @Author wyp168
 * @Date 2022/6/26 12:55
 */
public class ReverseBits {
    public static void main(String[] args) {
        System.out.println(reverseBits(1));
    }

    public static int reverseBits(int x) {
        //定义一个变量，封装结果
        int res = 0;
        //循环32次，每次将原x的开头一位移除，放到res的尾部
        for (int i = 0; i < 32; i ++) {
            res = res << 1;
            res |= (x & 1);
            x = x >> 1;
        }
        return res;
    }
}
